/*$(function () {
    $('#quantity').on('blur', function (){
        $.ajax({
            type     : "GET",
            url      : "cartUpdate?quantity="+ document.getElementById("quantity").value,
            success  :function (data){
                let array = data.split(",");
                let quantity = document.getElementById("quantity");
                let total= document.getElementById("total");
                let subtotal= document.getElementById("subtotal");

                //quantity.innerText= array[0];
                total.innerText= array[1];
                subtotal.innerText= array[2];
            }
        });
    });
});
*/
var xhr;
var number;
function updateCart(index){
    let quantity = document.getElementById("quantity" + index).value;
    number= index;
    xhr= new XMLHttpRequest();
    xhr.onreadystatechange= processResponse;
    console.log(quantity)
    xhr.open("GET","cartUpdate?quantity="+ quantity+"&itemNum="+number, true);
    xhr.send(null);
}

function processResponse() {
    if (xhr.readyState === 4) {
        if (xhr.status === 200) {
            var resp = xhr.responseText;
            var array = resp.split(",");
            console.log(resp);
            var quantity = document.getElementById("quantity"+number);
            var total = document.getElementById("total"+number);
            var subtotal = document.getElementById("subtotal");

            quantity.innerText = array[0];
            total.innerText = "$"+array[1];
            subtotal.innerText = "Sub Total: $"+array[2];
        }
    }
}
